export class TreeCheckBox  extends React.Component{


    state={
        checked:0
    }

    checked=(state)=>{
       this.setState({checked:state})
    }

    className=()=>{
        if(this.state.checked===0){
            return "far fa-square";
        }
        if(this.state.checked===1){
            return "far fa-check-square";
        }
        if(this.state.checked===2){
            return "fas fa-check-square";
        }
        return "far fa-square"
    }
    selected=()=>{
        return this.state.checked;
    }
    setVal=(val)=>{
        this.state.checked=val;
        this.setState(this.state);
    }
    onClick=(e)=>{
        if(this.state.checked===1||this.state.checked===2){
            this.state.checked=0;
        }else{
            this.state.checked=1;
        }
        if(this.props.onClick){
            this.props.onClick(this.state.checked);
        }
        this.setState(this.state);

    }
    render(){
        return <i onClick={this.onClick} onDoubleClick={(e)=>{
            e.stopPropagation();
            e.nativeEvent.stopImmediatePropagation();
         }
        } className={this.className()} style={{marginRight:'0.3rem'}}></i>
    }
}